package com.zxl.manager.privacy.utils;

import android.app.Activity;
import android.app.Application;
import android.os.Bundle;

import com.zxl.manager.privacy.utils.base.BaseActivityLifecycle;

/**
 * Created by Administrator on 2016/8/30.
 */
public class ActivityLifecycle extends BaseActivityLifecycle {

    private Activity mActivity;

    private static ActivityLifecycle sInstance;

    public static void registerActivityLifecycleCallbacks(Application application) {
        if (null == sInstance) {
            sInstance = new ActivityLifecycle();
            application.registerActivityLifecycleCallbacks(sInstance);
        }
    }

    @Override
    public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
        super.onActivityCreated(activity, savedInstanceState);
        mActivity = activity;
    }

    @Override
    public void onActivityDestroyed(Activity activity) {
        super.onActivityDestroyed(activity);
        mActivity = null;
    }

    public static Activity getActivity() {
        if (null != sInstance) {
            return sInstance.mActivity;
        }
        return null;
    }
}
